package com.xmy.cultivate.util;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtil {

    /**
     * 判断两个值的季度相差多少
     */
    public static Integer diffQuarter(Map<String,Integer> map){
        Integer oldYear = map.get("oldYear");
        Integer oldNum = map.get("oldNum");
        Integer newYear = map.get("newYear");
        Integer newNum = map.get("newNum");

        Integer diffYear = newYear - oldYear;
        Integer diffNum = (newYear - oldYear) * 4 + newNum - oldNum;

        return diffNum;
    }

    /**
     * 获取学段id
     * @param yearClassId
     * @return
     */
    public static Integer getGradeSectionId(Integer yearClassId){
        //yearClassId:少儿:0,1,2;小学:3,4,5,6;初中7,8,9;高中:10,11,12

        Integer[][] arr={{0,1,2},{3,4,5,6},{7,8,9},{10,11,12}};
        Integer rs = null;
        for (int i=0;i<arr.length;i++){
            Set<Integer> set = new HashSet<Integer>(Arrays.asList(arr[i]));
            if (set.contains(yearClassId)){
                rs = i;
                break;
            }
        }
        return rs;
    }

    /**
     * 获取科目
     * @param id
     * @return
     */
    public static String getLessonTypeName(Integer id){
        String[] dataArr = new String[]{"","精品课","智能课","刷题班"};
        String name = "";
        if(id>=0 && id<dataArr.length){
            name =dataArr[id];
        }
        return name;
    }

    public static String replaceGradeName(String gradeName,String studentName){
        //String text = "这是一个示例文本【第一组数据】和其他数据【第二组数据】结束。";
        Pattern pattern = Pattern.compile("【(.*?)】");
        Matcher matcher = pattern.matcher(gradeName);
        String keyword1 = "";
        while (matcher.find()) {
            //System.out.println(matcher.group(1));
            keyword1 = matcher.group(1);
        }
        if (StringUtils.isNotBlank(keyword1)){
            gradeName = gradeName.replace(keyword1,studentName);
        }
        return gradeName;
    }
}
